<template>
  <el-container class="pageWrapper">
    <!-- 左侧 -->
    <el-aside width="200px">
      <h2>你的后台你做主</h2>
      <el-radio-group v-model="isCollapse" style="margin-bottom: 100px">
        <el-radio-button :label="false">展开</el-radio-button>
        <el-radio-button :label="true" hide-timeout="1000"
          >收起</el-radio-button
        >
      </el-radio-group>
      <h3>文章管理</h3>
      <el-menu class="el-menu-vertical-demo" :collapse="isCollapse">
        <el-menu-item
          index="2"
          @click="$router.push('/postlist').catch((err) => {})"
        >
          <i class="el-icon-menu"></i>
          <span slot="title">文章列表</span>
        </el-menu-item>

        <el-menu-item
          index="4"
          @click="$router.push('/editpost').catch((err) => {})"
        >
          <i class="el-icon-setting"></i>
          <span slot="title">发表文章</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <!-- 右测主体部分 -->
    <el-container>
      <el-header class="header">
        <img
          v-if="userInfo.head_img"
          :src="$axios.defaults.baseURL + userInfo.head_img"
          alt=""
        />
        <img
          v-else
          src="../images/fa02c509aa9e05cac9bba6ee98fa9d6a.png"
          alt=""
        />
        <p>{{ userInfo.nickname }}</p>
        <span @click="retreat">退出</span>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      userInfo: [],
    };
  },
  created() {
    this.$axios({
      url: "/user/" + localStorage.getItem("userId"),
    }).then((res) => {
      console.log(res.data);
      this.userInfo = res.data.data;
    });
  },
  methods: {
    retreat() {
      this.$router.replace("/login");
      localStorage.clear();
      this.$message("已退出");
    },
  },
};
</script>

<style lang="less" scoped>
.pageWrapper {
  min-height: 100vh;
  h2 {
    line-height: 65px;
  }
  h3 {
    margin-top: -100px;
    line-height: 60px;
  }
  .header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-right: 20px;
    img {
      width: 45px;
      height: 45px;
      border-radius: 50%;
      object-fit: cover;
      cursor: pointer;
    }
    p {
      font-size: 16px;
      margin: 0 10px;
    }
    span {
      cursor: pointer;
    }
  }
}
.el-header,
.el-footer {
  background-color: #e68ea8;
  color: #fff;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #e76581;
  color: #fff;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  padding: 80px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-menu-vertical-demo {
  width: 100%;
  background-color: #e76581;

  .el-icon-menu,
  .el-icon-setting {
    color: #ccc;
  }
}
.el-menu-item:hover {
  background-color: #fa813b;
}
.el-menu {
  border: none;
}
</style>
